package jp.ac.segakuen.tags;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.Tag;

import jp.ac.segakuen.PMF;
import jp.ac.segakuen.SelectListTable;

public class examinSelectTagServlet implements Tag {

	private PageContext pageContext;
	private Tag parentTag;
	
	public int doEndTag() throws JspException {
	     return EVAL_PAGE;
	}

	@SuppressWarnings("unchecked")
	public int doStartTag() throws JspException {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		String query = "select from jp.ac.segakuen.SelectListTable where displayPlaceHolder == 'examdate' order by sortOrder ASC";
		List<SelectListTable> selectlist = (List<SelectListTable>) pm.newQuery(query).execute();
	    try {
	    	JspWriter out = pageContext.getOut();
	    	out.print("<select name=\"参加希望日\" id=\"kibo\" /> ");
	    	out.print("<option selected>--選択してください----------------</option>"); 
	       if (selectlist.isEmpty()) {
         	 	out.print("<option>----------</option>");   
	       }else{
	    	   for (SelectListTable l : selectlist) {

	    		   out.print("<option value=\"");
			    	out.print(l.getListText());
	   	    		out.print("\">");
		    		out.print(l.getListText());
		   	    	out.print("</option>");
			    }
	
	    	}
	       out.print("</select>"); 
	      } catch(Exception e) {
	        throw new JspException(e.getMessage());
	      }
	        return SKIP_BODY;
	}

	public Tag getParent() {
		return this.parentTag;
	}

	public void release() {


	}

	public void setPageContext(PageContext pageContext) {

		this.pageContext = pageContext;
	}

	public void setParent(Tag parentTag) {

		this.parentTag = parentTag;
	}

}
